﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_ShippingListController : BaseApiController
    {
        #region DI

        public PB_ShippingListController(IPB_ShippingListBusiness pB_ShippingListBus)
        {
            _pB_ShippingListBus = pB_ShippingListBus;
        }

        IPB_ShippingListBusiness _pB_ShippingListBus { get; }

        #endregion

        #region 获取
        /// <summary>
        /// 根据楼号查询主从表清单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_ShippingList>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_ShippingListBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 根据楼号绑定发货单所属清单主从表
        /// </summary>
        /// <param name="id">发货通知单ID</param>
        /// <param name="DesignId">清单id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PB_DeliverGoodDetailDTO> GetDataListByBuildNo(string id,string DesignId)
        {
            return await _pB_ShippingListBus.GetDataListByBuildNoAsync(id, DesignId);
        }

        [HttpPost]
        public async Task<PB_ShippingList> GetTheData(IdInputDTO input)
        {
            return await _pB_ShippingListBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_ShippingList data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ShippingListBus.AddDataAsync(data);
            }
            else
            {
                await _pB_ShippingListBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_ShippingListBus.DeleteDataAsync(ids);
        }


        /// <summary>
        /// 设计清单下的发货通知
        /// </summary>
        /// <param name="data">保存设计清单及明细</param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveMaterialData(SaveMaterialData data)
        {
            if (data.PId.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_ShippingListBus.AddMaterialData(data);
            }
            else
            {
                await _pB_ShippingListBus.UpdateMaterialData(data);
            }
        }


        /// <summary>
        /// 通过清单编号获取发货信息
        /// </summary>
        /// <param name="ProjectId">设计清单</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<DataTypeInfo>> GetDataLists(string ProjectId)
        {
            var res = await _pB_ShippingListBus.GetDataLisJson(ProjectId);
            return res;
        }
        /// <summary>
        /// 通过发货单获取信息
        /// </summary>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<DataTypeInfo>> GetShippingOrder(string ProjectId)
        {
            var res = await _pB_ShippingListBus.GetShippingOrder(ProjectId);
            return res;
        }
        #endregion
    }
}